package com.ruoyi.project.poem.poemuserinfo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.poem.poemuserinfo.domain.PoemUserInfo;
import com.ruoyi.project.poem.poemuserinfo.service.IPoemUserInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 诗词用户信息Controller
 * 
 * @author shixiangwen
 * @date 2022-10-11
 */
@Controller
@RequestMapping("/poem/poemuserinfo")
public class PoemUserInfoController extends BaseController
{
    private String prefix = "poem/poemuserinfo";

    @Autowired
    private IPoemUserInfoService poemUserInfoService;

    @RequiresPermissions("poem:poemuserinfo:view")
    @GetMapping()
    public String poemuserinfo()
    {
        return prefix + "/poemuserinfo";
    }

    /**
     * 查询诗词用户信息列表
     */
    @RequiresPermissions("poem:poemuserinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PoemUserInfo poemUserInfo)
    {
        startPage();
        List<PoemUserInfo> list = poemUserInfoService.selectPoemUserInfoList(poemUserInfo);
        return getDataTable(list);
    }

    /**
     * 导出诗词用户信息列表
     */
    @RequiresPermissions("poem:poemuserinfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PoemUserInfo poemUserInfo)
    {
        List<PoemUserInfo> list = poemUserInfoService.selectPoemUserInfoList(poemUserInfo);
        ExcelUtil<PoemUserInfo> util = new ExcelUtil<PoemUserInfo>(PoemUserInfo.class);
        return util.exportExcel(list, "poemuserinfo");
    }

    /**
     * 新增诗词用户信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存诗词用户信息
     */
    @RequiresPermissions("poem:poemuserinfo:add")
    @Log(title = "诗词用户信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PoemUserInfo poemUserInfo)
    {
        return toAjax(poemUserInfoService.insertPoemUserInfo(poemUserInfo));
    }

    /**
     * 修改诗词用户信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PoemUserInfo poemUserInfo = poemUserInfoService.selectPoemUserInfoById(id);
        mmap.put("poemUserInfo", poemUserInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存诗词用户信息
     */
    @RequiresPermissions("poem:poemuserinfo:edit")
    @Log(title = "诗词用户信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PoemUserInfo poemUserInfo)
    {
        return toAjax(poemUserInfoService.updatePoemUserInfo(poemUserInfo));
    }

    /**
     * 删除诗词用户信息
     */
    @RequiresPermissions("poem:poemuserinfo:remove")
    @Log(title = "诗词用户信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(poemUserInfoService.deletePoemUserInfoByIds(ids));
    }
}
